#include<iostream>
#include<string>
#include<pthread.h>
#include<unistd.h>
#include<cstdio>

using namespace std;

int x = 10;

void showName(const string& name)
{
    cout<<name<<"运行中...pid:"<<getpid()<<" "<<x<<endl;
}

void* pthreadRun(void* args)
{
    const string name = (char*)args;
    while(1)
    {
        showName(name);
        sleep(1);
    }
}

int main()
{
    pthread_t tid[5];
    char name[64];
    for(int i = 0;i<5;i++)
    {
        snprintf(name,sizeof(name),"%s_%d","thread",i+1);
        
        pthread_create(tid+i,NULL,pthreadRun,(void*)name);
        sleep(1);
    }

    while(1)
    {
        cout<<"主线程运行中....pid："<<getpid()<<endl;
        sleep(3);
    }
    return 0;
}